package 尚硅谷.juc.test17;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.TimeUnit;

@Slf4j
public class BlockQueueDemo {

    public static void main(String[] args) throws InterruptedException {
        MyData myData=new MyData(new ArrayBlockingQueue<>(10));

        new Thread(()->{
            try {
                myData.myProd();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }).start();

        new Thread(()->{
            try {
                myData.myConsumer();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }).start();

        TimeUnit.SECONDS.sleep(5);
        log.info("5秒时间到，main线程将消息队列叫停..............................");
        myData.stop();
    }
}
